package edu.itesm.mx.servicios;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ColumnasAdaptador extends ArrayAdapter<Object> {
	private final Activity activity;
	private final List<?> objetos;
	
	public ColumnasAdaptador(Activity activity, List objetos) {
		super(activity, R.layout.columnas, objetos);
		this.activity = activity;
		this.objetos = objetos;
	}

	@Override
	public View getView(int posicion, View convertView, ViewGroup parent) {
		//return super.getView(position, convertView, parent);
		View vistaFila = convertView;
		DatosView fdView = null;
		
		if(vistaFila == null) {
			LayoutInflater inflater = activity.getLayoutInflater();
			vistaFila = inflater.inflate(R.layout.columnas, null);
			
			fdView = new DatosView();
			fdView.columna1 = (TextView) vistaFila.findViewById(R.id.columna1);
			fdView.columna2 = (TextView) vistaFila.findViewById(R.id.columna2);
			
			vistaFila.setTag(fdView);
		} else {
			fdView = (DatosView) vistaFila.getTag();
		}
		
		ColumnasDatos datos = (ColumnasDatos) objetos.get(posicion);
		fdView.columna1.setText(datos.getColumna1());
		fdView.columna2.setText(datos.getColumna2());
		
		return vistaFila;
	}
	
	protected static class DatosView {
		protected TextView columna1;
		protected TextView columna2;
	}
}